package com.wanxi.Internet.group;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.UUID;

public class Receive {
    public static void main(String[] args) {

        try {

            System.out.println(UUID.randomUUID().toString() + "组播接收端启动");
            MulticastSocket multicastSocket = new MulticastSocket(1948);

            byte[] bytes = new byte[1024 * 64];

            DatagramPacket datagramPacket = new DatagramPacket(bytes, 0, bytes.length);

            InetAddress inetAddress = InetAddress.getByName("224.0.2.0");

            multicastSocket.joinGroup(inetAddress);
            multicastSocket.receive(datagramPacket);

            String s = new String(datagramPacket.getData(), 0, datagramPacket.getLength());
            System.out.println("信息为： " + s);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
